package com.shqcjd.preinstallmobile.ui.activity;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.flyco.tablayout.SegmentTabLayout;
import com.shqcjd.preinstallmobile.R;
import com.shqcjd.preinstallmobile.api.ApiService;
import com.shqcjd.preinstallmobile.helper.rxjavahelper.RxObserver;
import com.shqcjd.preinstallmobile.helper.rxjavahelper.RxSchedulersHelper;
import com.shqcjd.preinstallmobile.model.ResponseData;
import com.shqcjd.preinstallmobile.model.eventbus.RefreshReddotEvent;
import com.shqcjd.preinstallmobile.model.pojo.DefectManageTypeBean;
import com.shqcjd.preinstallmobile.model.pojo.EquipmentListBean;
import com.shqcjd.preinstallmobile.ui.adapter.EquipmentListAdapter;
import com.shqcjd.preinstallmobile.ui.base.BaseActivity;
import com.shqcjd.preinstallmobile.ui.base.BasePresenter;
import com.shqcjd.preinstallmobile.ui.fragment.equipmentmanage.EquipmentManagerfragment;
import com.shqcjd.preinstallmobile.ui.fragment.equipmentmanage.InspectioNtrackFragment;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import io.reactivex.disposables.Disposable;

/**
 * 设备管理
 */
public class EquipmentListActivity extends BaseActivity {
    @BindView(R.id.iv_toolbar_back)
    ImageView tvIncludeFinish;
//    @BindView(R.id.sp_euipment_list_type)
//    Spinner spEuipmentListType;
//    @BindView(R.id.sp_euipment_list_time)
//    Spinner spEuipmentListTime;
//    @BindView(R.id.sp_euipment_list_state)
//    Spinner spEuipmentListState;
//    @BindView(R.id.rv_equipment_list)
//    RecyclerView rvEquipmentList;
//    @BindView(R.id.sr_equipment_list)
//    SwipeRefreshLayout srEquipmentList;
//    @BindView(R.id.rl_isnull)
//    RelativeLayout rlIsnull;
//    @BindView(R.id.et_defect_manage)
//    EditText etDefectManage;
    @BindView(R.id.tl_title)
    SegmentTabLayout tl_title;
    @BindView(R.id.fl_change)
    FrameLayout fl_change;

    private Context context;
    private int page = 1;
    private int isRefreshOrLoadMore = 0;//0代表刷新  1代表加载更多
    private EquipmentListAdapter equipmentListAdapter;
    private List<EquipmentListBean.ItemsBean> mList = new ArrayList<>();

    private int eId = 0;

    List timeList = new ArrayList<String>();
    List stateList = new ArrayList<String>();
    private int timeId = 0, stateId = 0;
    private String strSearch = "";

    List typeList = new ArrayList<String>();
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    List<DefectManageTypeBean> tList = new ArrayList<>();
    private String[] mTitles = {"设备管理", "巡检轨迹"};
    private boolean jpushFlag = false;
    private String sysMsgId;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_equipment_list;
    }

    @Override
    public void init() {
        super.init();
    }

    @Override
    public void initView() {
        super.initView();
        context = this;
        jpushFlag = getIntent().getBooleanExtra("jpush", false);
        sysMsgId = getIntent().getStringExtra("sysMsgId");
        mFragments.add(EquipmentManagerfragment.newInstance(jpushFlag));
        mFragments.add(InspectioNtrackFragment.newInstance());
        tl_title.setTabData(mTitles,this, R.id.fl_change, mFragments);
//        tl_title.setCurrentTab(1); 默认选中页


        tvIncludeFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        //如果从通知栏进入则设置消息已读
        if (sysMsgId != null) {
            //设置首页消息红点消失
            EventBus.getDefault().postSticky(new RefreshReddotEvent(false));
            setSysMsg();
        }

    }

    /**
     * 设置系统消息已读
     */
    private void setSysMsg() {
        ApiService.setSysMsgRead(sysMsgId)
                .compose(RxSchedulersHelper.io_main())
                .subscribe(new RxObserver<ResponseData>() {
                    @Override
                    public void _onSubscribe(Disposable d) {
                        super._onSubscribe(d);
                    }

                    @Override
                    public void _onNext(ResponseData retData) {
                    }

                    @Override
                    public void _onError(String errorMessage) {
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                    }
                });
    }
}
